title = "分类产品列表页"
url = "/:slug|[a-z0-9\-]+-c-\d+.html$"
description = '分类产品列表页'
layout = 'default'
==
use Jason\Ccshop\Controllers\Categories;
use Jason\Ccshop\Models\Category;
use Jason\Ccshop\Controllers\Filters;
use Jason\Ccshop\Models\Product;
function onStart() {

    $slugArr = explode('-', str_replace('.html', '', $this->param('slug')));

    $id = array_pop($slugArr);

    array_pop($slugArr);

    $condition = ['id' => $id];

    $this['paramKey'] = join('-', $slugArr);

    $category = Categories::getCategory($condition);

    if ($category && $category['is_enabled'] ==1) {

        $pids = get('id_sort')?get('id_sort'):null;

        $pageNumber = get('page')?get('page'):1;

        if(!empty($pids)){
            Cookie::queue('idssort',$pids);
            Cookie::queue('cid',$id);
            Cookie::queue('pagenumber',$pageNumber);
        }else{
            $pageNumber = Cookie::get('pagenumber');
            $cid = Cookie::get('cid');
            $currentPage = get('page')?get('page'):1;
            if($currentPage==$pageNumber && $id==$cid){
                $pids = Cookie::get('idssort');
            }
        }

        $pida = explode(',',$pids);
        $pd = Product::InStock()->whereIn('id',$pida)->get();

        $this['adproducts'] = $pd;
        $this['pida'] = $pida;
        $this['category'] = $category;
        if($this['paramKey'] == 'isStar'){
            $this['isStar'] = true;
        }else{
            if ($this['paramKey'] != $category['slug']) {
            $orderArr = Filters::parseFilterKeyParams($this['paramKey']);
            if (count($orderArr) == 2) {
                //默认排序为从大到小
                if($orderArr[0]=='sort'){
                    $orderArr[1] = 'desc';
                }
                    $order = [$orderArr[0] => $orderArr[1]];
                }
            }
        }

        $this['order'] = isset($order) ? $order : ['sort' => 'desc'];

    } else {

        return redirect('/404');

    }

    $this['domain']= \Config::get('app.url');

}
==
{% set products = catalog.getCategoryProducts(category, order) %}
{% set per = get('per', 20) %}
{% set currentPage = get('page', 1) %}
{% set totalPages = ceil(products.total/products.per_page) %}
{% put page_title %}{{ category.page_title }} - {% default %}{% endput %}
{% put pageurl %}{{ catalog.canonicalValue(category.url, 'category')|raw }}{% endput %}
{% put nextprePageUrl %}
{% if products.nextPageUrl %}
<link rel="next" href="{{ products.nextPageUrl }}">
{% endif %}
{% endput %}
{% put meta_keywords %}{{ category.meta_keywords }}{% endput %}
{% put meta_description %}{{ category.meta_description }}{% endput %}
<div id="contents">
    {% partial 'header-campaign-message' %}
    {% partial 'breadcrumbs' product=product categories=product.categories %}
    {% partial 'catagory/ad-product' adproducts=adproducts pida=pida  pid=products.data[0].id %}
    <section>
        <div class="m10 mt0" style="position:relative;">
            <div class="search_disp_sort_wrap box_list">
                <div class="search_disp_sort_txt">{{ 'Sort by'|_ }}</div>
                <div class="search_disp_limit_select selectCommonWrap box_list_main">
                    <ul class="select_common">
                        <li>
                        {% if starts_with(this.param.slug, 'price_asc') %}{{ 'Price(low-high)'|_ }}
                        {% elseif starts_with(this.param.slug, 'newness_desc') %}{{ 'New arrvival'|_ }}
                        {% elseif starts_with(this.param.slug, 'rating_desc') %}{{ 'Popularity'|_ }}
                        {% elseif starts_with(this.param.slug, 'popular_desc') %}{{ 'Best selling'|_ }}
                        {% else %}{{ 'Default'|_ }}
                        {% endif %}
                        </li>
                    </ul>
                </div>
            </div>
            <div id="categorySort" class="box_list_main">
                <a href="{{ 'catalog/filter-feature'|page({slug: 'sort_asc-c-'~ category.id ~'.html'}) }}">{{ 'Default'|_ }}</a>
                <a href="{{ 'catalog/filter-feature'|page({slug: 'price_desc-c-'~ category.id ~'.html'}) }}">{{ 'Price(high-low)'|_ }}</a>
                <a href="{{ 'catalog/filter-feature'|page({slug: 'price_asc-c-'~ category.id ~'.html'}) }}">{{ 'Price(low-high)'|_ }}</a>
                <a href="{{ 'catalog/filter-feature'|page({slug: 'newness_desc-c-'~ category.id ~'.html'}) }}">{{ 'New arrvival'|_ }}</a>
                <a href="{{ 'catalog/filter-feature'|page({slug: 'rating_desc-c-'~ category.id ~'.html'}) }}">{{ 'Popularity'|_ }}</a>
                <a href="{{ 'catalog/filter-feature'|page({slug: 'popular_desc-c-'~ category.id ~'.html'}) }}">{{ 'Best selling'|_ }}</a>
            </div>
        </div>
        <div class="searchpageConditionArea simple_list_item_top clearfix">
            <div class="fl">
                <p class="fnt_small mv10 lh120">{{ 'total'|_ }}：{{ products.total }}{{ 'items'|_ }}</p>
            </div>
        </div>
        <ul id="productsContent1" class="list_product_box clearfix mt5 twoColumn">
            {% partial 'catagory/loadmoreproducts' products = products %}

        </ul>
        <form id="ajaxLoadFormoreproducts">
            <input id="ajaxLoadFormoreproducts_page" type="hidden" name="page" value="2" />
            <input id="ajaxLoadFormoreproducts_sort" type="hidden" name="order" value="sort_asc" />
            <input id="ajaxLoadFormoreproducts_category" type="hidden" name="categoryId" value="{{ category.id }}" />
        </form>
        <div class="load_click load_click_c" id="view_more_preorder">
            <div id="wait_for_load_list_preorder" style="margin:10px 0;text-align:center;">
                <span id="wait_for_load_list_preorder_text" style="display: none">
                {{ 'Products loading has finished '|_ }}
                </span>
                <span id="wait_for_load_list_preorder_img" style="display: none">
                <img  src="{{ 'assets/images/loadingAnimation.gif'|theme }}" style="width:26px;height:26px;">
                </span>
            </div>
        </div>
        <button id="ajaxLoadFormoreproductsbutton" {% if totalPages <= 1 %}style="display:none"{% endif %} style="position:relative;width:95%;margin:10px auto;z-index:99;outline:none;font-size:14px;height:35px;">{{ 'See more'|_ }}</button>


        <nav class="corePager">
            <div class="corePager_btn"></div>
            <div class="corePager_info">{{ 'Total '|_ }}{{ products.total }}{{ ' items'|_ }}</div>
            <div class="corePager_btn"></div>
        </nav>
    </section>
</div>
<link href="{{ 'assets/css/index.css'|theme }}" rel="stylesheet" type="text/css" />
<link href="{{ 'assets/css/shop.css'|theme }}" rel="stylesheet" type="text/css" />
<link href="{{ 'assets/css/swiper.min.css'|theme }}" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="{{ 'assets/js/shop_product.js'|theme }}"></script>
<script type="text/javascript" src="{{ 'assets/js/swiper.min.js'|theme }}"></script>
<script type="text/javascript">
    $(function () {
        $("ul.select_common li").click(function(){
            $("#categorySort").toggle();
        });

        $(".sxSort").click(function(){
            $('body').addClass ("push-overflow");
        });

        $(".modal_list_close").click(function(){
            $('body').removeClass("push-overflow");
        });

        $("#lean_overlay").click(function(){
            $('body').removeClass("push-overflow");
        });

        var mySwiper2 = new Swiper ('.adProductsSwiper', { //所有2个布局的轮播
            direction: 'horizontal',
            loop: false,
            slidesPerView:2,
            paginationClickable:true,
            nextButton: '.swiper-button-next',
            prevButton: '.swiper-button-prev',
            
        })   
    });
</script>
